package com.zhiyou100.mapper;

import com.zhiyou100.entity.Worker;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author yang
 */
public interface WorkerMapper {
    @Select("select worker_id     workerId,\n" +
            "       worker_name   workerName,\n" +
            "       worker_salary workerSalary,\n" +
            "       worker_sex    workerSex,\n" +
            "       worker_age    workerAge\n" +
            "from worker;\n")
    List<Worker> getAll1();

    /**
     * 开启  支持数据库列名_分割与实体类属性名驼峰命名转换 后
     * <setting name="mapUnderscoreToCamelCase" value="true"/>
     *
     * @return List<Worker>
     */
    @Select("select *\n" +
            "from worker;")
    List<Worker> getAll2();


    @Select("select *\n" +
            "from worker;")
    @Results(
            id = "getAll3",
            value = {
                    @Result(column = "worker_id", property = "workerId"),
                    @Result(column = "worker_name", property = "workerName"),
                    @Result(column = "worker_age", property = "workerAge"),
                    @Result(column = "worker_sex", property = "workerSex"),
                    @Result(column = "worker_salary", property = "workerSalary"),
            }
    )
    List<Worker> getAll3();


    @Select("select *\n" +
            "from worker\n" +
            "where worker_name = #{na}\n" +
            "  and worker_age = #{age};")
    List<Worker> getAll4(@Param("na") String name, @Param("age") Integer age);

    @Delete("delete from worker where worker_id=#{0}")
    int deleteOne(int wid);

    @Insert("insert into worker values(null,#{workerName},#{workerAge},#{workerSex},"
            + "#{workerSalary})")
    int addOne(Worker w);

    @Update("update worker set  worker_name=#{workerName} where worker_id=#{workerId}")
    int updateOne(Worker w);

    @Select("select *\n" +
            "from worker\n" +
            "where worker_id = #{id};")
    Worker getOneByWid(@Param("id") int wid);


}